package com.gonsin.gview.example.config;

import com.gonsin.gview.common.config.GViewResourceProperties;
import com.gonsin.gview.logic.config.GViewFileProperties;
import com.gonsin.gview.logic.config.GViewMenuService;
import com.gonsin.gview.model.menu.GViewMenu;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

@Configuration
public class GViewConfig {

    @Bean
    public GViewFileProperties gViewFileProperties(){
        GViewFileProperties properties = new GViewFileProperties();
        properties.setTempPath("C://temp");
        return properties;
    }

    @Bean
    @ConditionalOnMissingBean
    public GViewResourceProperties defaultResourceProperties(){
        GViewResourceProperties resourceProperties = new GViewResourceProperties();
        resourceProperties.setDefaultPassword("123");
        resourceProperties.setDefaultUsername("admin");
        resourceProperties.setTitle("GView使用例子");
        resourceProperties.setTitleEn("GView Demo");
        return resourceProperties;
    }

    @Bean
    public GViewMenuService gViewMenuConfig(){
        GViewMenuService config = new GViewMenuService() {

            @Override
            public List<GViewMenu> getMenus(HttpServletRequest request) {
                List<GViewMenu> menus = new ArrayList<>();
                menus.add(new GViewMenu("SYSTEM", "系统管理", null, "", "el-icon-menu"));
                menus.add(new GViewMenu("SYSTEM_GROUP", "权限设置", "SYSTEM", "view?viewName=GroupBean", "el-icon-menu"));
                menus.add(new GViewMenu("SYSTEM_ACCOUNT", "账号设置", "SYSTEM", "view?viewName=UserBean", "el-icon-menu"));
                menus.add(new GViewMenu("SYSTEM_MY_ACCOUNT", "我的设置", "SYSTEM", "view?viewName=MyUser", "el-icon-menu"));
                menus.add(new GViewMenu("SYSTEM_SETTING", "系统设置", "SYSTEM", "view?viewName=GlobalSetting", "el-icon-menu"));
                return menus;
            }
        };
        return config;
    }
}
